﻿using KAKA.Domain;
using Morus.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;

namespace KAKA.Repository
{
    public interface ICategoryRepository : IRepository<Category>
    {
        Category Get(Guid id);

        IEnumerable<Category> GetAll();
    }

    public class CategoryRepository : Repository<Category>, ICategoryRepository
    {
        public CategoryRepository(Database database)
            : base(database)
        {
        }

        public override void Add(Category aggregateRoot)
        {
            base.Add(aggregateRoot);
        }

        public Category Get(Guid id)
        {
            return base.Get<Category>(Spec<Category>.Eval(r => r.Id == id));
        }

        public new IEnumerable<Category> GetAll()
        {
            return base.GetAll().OrderBy(r => r.Name);
        }
    }
}
